﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 数据字典值
    /// </summary>
    public partial class CF_EnumItem : BusEntity
    {
        /// <summary>
        /// 公司Id
        /// </summary>
        public string CompanyId { get; set; }
        /// <summary>
        /// 数据字典
        /// </summary>
        public string EnumId { get; set; }
        /// <summary>
        /// 显示名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 字典编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }
        /// <summary>
        /// 配置参数
        /// </summary>
        public string Config { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 系统必须
        /// </summary>
        public bool IsSystem { get; set; }
    }

    public partial class CF_EnumItem : BusEntity
    {
        /// <summary>
        /// 仓库
        /// </summary>
        //public Bas_Whse Whse { get; set; }
        public CF_Enum Enum { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class CF_EnumItemTypeConfig : BusEntityTypeConfig<CF_EnumItem>, IEntityTypeConfiguration<CF_EnumItem>
    {
        public override void Configure(EntityTypeBuilder<CF_EnumItem> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            //builder.HasOne(o => o.Whse).WithMany().HasForeignKey(p => p.WhseId).OnDelete(DeleteBehavior.ClientCascade);
            builder.HasOne(p => p.Enum).WithMany(m => m.EnumItems).HasForeignKey(p => p.EnumId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.EnumId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Sort).HasDefaultValue(0);
            builder.Property(p => p.Config).HasMaxLength(EntityDefinition.DefLargeColLen).IsRequired(false);
            builder.Property(p => p.Remark).HasMaxLength(EntityDefinition.DefMiddleColLen);
            builder.Property(p => p.IsSystem).HasDefaultValue(false);
            #endregion

            #region 备注
            builder.HasComment("数据字典值");
            builder.Property(p => p.EnumId).HasComment("数据字典");
            builder.Property(p => p.Name).HasComment("显示名称");
            builder.Property(p => p.Code).HasComment("字典编码");
            builder.Property(p => p.Sort).HasComment("排序");
            builder.Property(p => p.Config).HasComment("配置参数");
            builder.Property(p => p.Remark).HasComment("备注");
            builder.Property(p => p.IsSystem).HasComment("系统必须");
            #endregion

            #region 种子数据
            #region Define
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_StationType01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_StationType", Name = "全自动", Code = "Automatic", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_StationType02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_StationType", Name = "半自动", Code = "SemiAutomatic", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_StationType03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_StationType", Name = "人工", Code = "Manual", Sort = 3, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号1", Code = "1", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号2", Code = "2", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号3", Code = "3", Sort = 3, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType04", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号4", Code = "4", Sort = 4, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType05", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号5", Code = "5", Sort = 5, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType06", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号6", Code = "6", Sort = 6, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType07", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号7", Code = "7", Sort = 7, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType08", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号8", Code = "8", Sort = 8, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType09", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号9", Code = "9", Sort = 9, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_EleCarType10", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_EleCarType", Name = "型号10", Code = "10", Sort = 10, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );
            #endregion
            #region Exec
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_AgvTaskType01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_AgvTaskType", Name = "背框", Code = "Box", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_AgvTaskType02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_AgvTaskType", Name = "背料", Code = "Material", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_AgvTaskStatus01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_AgvTaskStatus", Name = "请求中", Code = "Start", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_AgvTaskStatus02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_AgvTaskStatus", Name = "已接收", Code = "Material", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_AgvTaskStatus03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_AgvTaskStatus", Name = "执行中", Code = "Material", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_AgvTaskStatus04", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_AgvTaskStatus", Name = "已完成", Code = "Material", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );
            #endregion
            #region Sys,CF
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Sex01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Sex", Name = "男", Code = "Boy", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Sex02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Sex", Name = "女", Code = "Girl", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_YesOrNo01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_YesOrNo", Name = "是", Code = "Yes", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_YesOrNo02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_YesOrNo", Name = "否", Code = "No", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_Config_Type01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_Config_Type", Name = "系统配置", Code = "System", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_Config_Type02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_Config_Type", Name = "用户配置", Code = "User", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_Config_Type03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_Config_Type", Name = "默认值配置", Code = "Default", Sort = 3, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "常量", Code = "Const", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "日期", Code = "Date", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "流水号", Code = "Serial", Sort = 3, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type04", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "流水号(日)", Code = "PerDay", Sort = 4, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type05", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "流水号(月)", Code = "PerMonth", Sort = 5, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type06", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "流水号(年)", Code = "PerYear", Sort = 6, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type07", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "随机数", Code = "Random", Sort = 7, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type08", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "参数", Code = "Parameter", Sort = 8, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type09", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_CF_CodeRule_Type", Name = "流水号(参数)", Code = "ParaSerial", Sort = 9, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_State01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_State", Name = "启用", Code = "Enable", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_State02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_State", Name = "停用", Code = "Disable", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Unit01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Unit", Name = "默认", Code = "EA", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Unit02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Unit", Name = "托", Code = "PL", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Unit03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Unit", Name = "箱", Code = "Box", Sort = 3, Remark = "", IsSystem = false, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Unit04", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Unit", Name = "件", Code = "Piece", Sort = 4, Remark = "", IsSystem = false, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Unit05", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Unit", Name = "包", Code = "Package", Sort = 5, Remark = "", IsSystem = false, CreateUserId = "1", ModifyUserId = "1" }
            );
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_UnitLevel01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_UnitLevel", Name = "基本单位", Code = "UL1", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_UnitLevel02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_UnitLevel", Name = "二级单位", Code = "UL2", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_UnitLevel03", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_UnitLevel", Name = "三级单位", Code = "UL3", Sort = 3, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_UnitLevel04", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_UnitLevel", Name = "四级单位", Code = "UL4", Sort = 4, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );
            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Rotation01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Rotation", Name = "先进先出", Code = "FIFO", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_Rotation02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_Rotation", Name = "后进先出", Code = "LIFO", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            builder.HasData(
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_SyncStatus01", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_SyncStatus", Name = "未同步", Code = "Active", Sort = 1, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" },
                new CF_EnumItem() { Id = $"{EntityDefinition.DefSysCode}_SyncStatus02", CompanyId = EntityDefinition.DefSysCode, EnumId = $"{EntityDefinition.DefSysCode}_SyncStatus", Name = "已同步", Code = "Synced", Sort = 2, Remark = "", IsSystem = true, CreateUserId = "1", ModifyUserId = "1" }
            );

            #endregion
            #endregion
        }
    }
}
